package com.faiz.algorithm;

public class Pi {

    public static double solution(int n) {
        double result = 0D;
        for (int i = 0; i <= n; i++) {
            result = result + (factorial(4 * n) * (26390 * n + 1103)) / (Math.pow(factorial(n), 4) * Math.pow(396, 4 * n));
        }
        return result * (Math.sqrt(8)/9801);
    }

    public static int factorial(int n) {
        if (n == 0) {
            return 1;
        }
        int result = 1;
        for (int i = 1; i <= n; i++) {
            result = result * i;
        }
        return result;
    }
}
